






#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int N = 2e5 + 10;
#define INF 0x3f3f3f3f;
typedef long long int ll;
#define close(); std::ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
//----------------------------------------------------------------------------//
int n;
void solve()
{
	cin >> n;
	string s;
	cin >> s;
	int ans = 0;
	for (int i = 0, j = 0; i < s.size(); i++)
	{
		if (s[j] != '0') j++;
		if (s[i] == '0' && i != j)
		{
			int cnt = 0;
			while (j <i)
			{
				if (s[j] == '1') cnt++;
				j++;
			}
			if (cnt < 2) ans += 2 - cnt;
		}
	}

	cout << ans << '\n';
}

int main()
{
	close();
	int T; cin >> T;
	while (T--) solve();
	return 0;
}
//0110110   ok
//01010 --->010 no